package com.gjy.design.observer.pull;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author gjy
 * @version 1.0
 * @since 2025-11-07 10:11:02
 */
public class CurrentConditionsDisplayPull implements Observer {
    private static final Logger log = LoggerFactory.getLogger(CurrentConditionsDisplayPull.class);
    
    private float temperature;
    private float humidity;
    private float pressure;
    private final Subject weatherData; // 持有主题引用以获取数据

    public CurrentConditionsDisplayPull(Subject weatherData) {
        this.weatherData = weatherData;
        weatherData.registerObserver(this);
    }

    @Override
    public void update() {
        // 主动从主题获取数据
        if (weatherData instanceof WeatherDataPull) {
            WeatherDataPull wd = (WeatherDataPull) weatherData;
            this.temperature = wd.getTemperature();
            this.humidity = wd.getHumidity();
            this.pressure = wd.getPressure();
        }
        display();
    }

    public void display() {
        log.info("当前条件（拉模型）: {}°C, 湿度: {}%, 气压: {}", temperature, humidity, pressure);
    }

}
